package com.tangyuan.niochat.server;

import com.tangyuan.niochat.common.Constants;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * Created on 2019-08-28
 *
 * @author fenghongyu
 */
public class ChatServer {

    public static void main(String[] args) {
        NioEventLoopGroup bossGroup = new NioEventLoopGroup();
        NioEventLoopGroup workerGroup = new NioEventLoopGroup();

        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(bossGroup, workerGroup)
                //指定IO模型
                .channel(NioServerSocketChannel.class)
                //对接受到的连接分配NioSocketChannel进行处理
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel channel) {
                        channel.pipeline().addLast(new ChatServerHandler());
                    }
                })
                //绑定端口号
                .bind(Constants.DEFAULT_SERVER_PORT);
    }
}
